package com.jy.wms.web;

import com.jy.wms.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.*;

@Controller
@RequestMapping("/instock")
public class WmsInstockRouter {
    @Autowired
    LoginService loginService;
    @RequestMapping(value = "instockOrder")
    public String instockOrder(Model model, HttpSession session){
        return  "instock/instockOrder/instockOrder";
    }
    @RequestMapping(value = "addSoOrder")
    public String toAddSoOrder(Model model, HttpSession session){
        return  "instock/instockOrder/addSoOrder";
    }

    @RequestMapping(value = "importInstockSo")
    public void importInstockSo(Model model, HttpSession session,HttpServletResponse res){
        String fileName = "upload.jpg";
        res.setHeader("content-type", "application/octet-stream");
        res.setContentType("application/octet-stream");
        res.setHeader("Content-Disposition", "attachment;filename=" + fileName);
        byte[] buff = new byte[1024];
        BufferedInputStream bis = null;
        OutputStream os = null;
        try {
            os = res.getOutputStream();
            bis = new BufferedInputStream(new FileInputStream(new File("d://"
                    + fileName)));
            int i = bis.read(buff);
            while (i != -1) {
                os.write(buff, 0, buff.length);
                os.flush();
                i = bis.read(buff);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (bis != null) {
                try {
                    bis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        System.out.println("success");
    }
}
